package com.wangsd.common.controller;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@Builder
@ApiModel(value = "返回说明")
@Slf4j
public class AjaxResult<T> {
    @ApiModelProperty(value = "200表示成功，其他失败")
    private int code;

    @ApiModelProperty(value = "返回数据")
    private T data;

    public static AjaxResult success(Object result) {
        AjaxResult data = AjaxResult.builder().code(200).data(result).build();
        //log.debug("返回数据={}", JSON.toJSONStringWithDateFormat(data, "yyyy-MM-dd hh:mm:ss"));
        return data;
    }

    public static AjaxResult fail(String message) {
        return AjaxResult.builder().code(500).data(message).build();
    }
}
